import cookie from 'js-cookie'
const userOptions = {
    namespaced: true,
    state:{
        token:''
    },
    actions:{
        setToken(context,val){
            context.commit('SETTOKEN',val)
        },
        getToken(context,val){
            context.commit('GETTOKEN',val)
        },
        clearToken(context,val){
            context.commit('CLEARTOKEN',val)
        }
    },
    mutations:{
        SETTOKEN(state,val){
            state.token = val
            cookie.set('token',val)
        },
        GETTOKEN(state,val){
            state.token = state.token || cookie.get('token')
        },
        CLEARTOKEN(state,val){
            state.token = ''
            cookie.remove('token')
        }
    },
    getters:{}
}

export default userOptions